<template>
  <el-card class="table-card" shadow="hover">
    <!-- 状态显示 -->
    <div class="status">
      <span class="status-label" :class="statusClass">{{ statusText }}</span>
    </div>

    <!-- 卡片内容 -->
    <div class="content">
      <!-- 餐桌编号 -->
      <div class="table-number">
        <span>{{ tableNumber }}</span>
      </div>
      <!-- 周转率和累计人数 -->
      <div class="info">
        <div class="rate">
          周转率: <span class="rate-value">{{ turnoverRate }}%</span>
        </div>
        <div class="count">
          累计人数: <span class="count-value">{{ totalPeople }}</span>
        </div>
      </div>
      <!-- 餐位状态及占用时间 -->
      <div class="seats">
        <div v-for="(seat, index) in seatStatuses" :key="index" class="seat">
          <span :class="seatStatusClass(seat.isOccupied)">
            {{ seatStatusText(seat.isOccupied) }}
          </span>
          <div class="seat-time">*{{ seat.time }}</div>
        </div>
      </div>
    </div>
  </el-card>
</template>

<script lang="ts">
import { defineComponent } from 'vue';

export default defineComponent({
  name: 'TableCard',
  props: {
    isOccupied: {
      type: Boolean,
      default: false
    },
    tableNumber: {
      type: Number,
      default: 1
    },
    seatStatuses: {
      type: Array as () => Array<{ isOccupied: boolean; time: string }>,
      default: () => [
        { isOccupied: false, time: '-' },
        { isOccupied: false, time: '-' }
      ]
    },
    turnoverRate: {
      type: Number,
      default: 56.3
    },
    totalPeople: {
      type: Number,
      default: 300
    }
  },
  computed: {
    statusText() {
      return this.isOccupied ? '就餐中' : '空位';
    },
    statusClass() {
      return this.isOccupied ? 'occupied' : 'available';
    }
  },
  methods: {
    seatStatusClass(isOccupied: boolean) {
      return isOccupied ? 'seat-occupied' : 'seat-available';
    },
    seatStatusText(isOccupied: boolean) {
      return isOccupied ? '已占用' : '空';
    }
  }
});
</script>

<style scoped>
.table-card {
  width: 360px;
  height: 155px; /* 调整高度适应每个座位的时间显示 */
  padding: 12px;
  border-radius: 10px;
  background-color: #f5f5f5; /* 浅灰色背景 */
  box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.2); /* 更明显的阴影 */
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-sizing: border-box;
}

/* 状态显示 */
.status {
  position: absolute;
  top: 0px;
  left: 8px;
}

.status-label {
  font-size: 24px;
  color: #ffffff;
  padding: 4px 8px;
  border-radius: 6px;
}

.occupied {
  background-color: #f8d7da;
  color: #721c24;
}

.available {
  background-color: #d4edda;
  color: #155724;
}

/* 卡片内容 */
.content {
  display: flex;
  justify-content: space-between;
  align-items: center;

  margin-top: 36px;
  margin-left: 0px;
}

.seats {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.seat {
  height: 36px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.seat span {
  width: 65px;
  font-size: 16px;
  padding: 2px 8px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.seat-occupied {
  background-color: #f8d7da;
}

.seat-available {
  background-color: #d4edda;
}

.seat-time {
  font-size: 12px;
  color: #888888;
  display: flex;
  align-items: center; /* 垂直居中对齐 */
  text-align: center;
}

/* 餐桌编号 */
.table-number {
  width: 75px;
  height: 75px;
  border-radius: 50%;
  background-color: #e0e0e0;

  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 42px;
  color: #555555;
}

/* 周转率和累计人数 */
.info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 22px;
}

.rate,
.count {
  font-size: 16px;
  color: #555555;
}

.rate-value {
  background-color: #d1c4e9; /* 浅紫色背景 */
  padding: 2px 8px;
  border-radius: 4px;
  color: #512da8;
}

.count-value {
  background-color: #bbdefb; /* 浅蓝色背景 */
  padding: 2px 8px;
  border-radius: 4px;
  color: #1565c0;
}
</style>
